#include "stdafx.h"
#include "libraries.h"

#include "Application.h"
#include "Filesystem.h"

using namespace Cvekas;

class SoundTest: public Application
{
public:
	SoundTest(HINSTANCE instance, const std::string& name, const std::string& log_filename)
		: Application(instance, name, log_filename)
	{
		Filesystem::init();
	}

	virtual ~SoundTest()
	{
	}

	virtual void initVideoDevice()
	{
		settings->insert("video", VideoSettings());

		(*settings)["video"]["ScreenWidth"] = 800;
		(*settings)["video"]["ScreenHeight"] = 600;
		(*settings)["video"]["VSync"] = false;
		(*settings)["video"]["Fullscreen"] = false;

		window = WindowPtr(new Window(instance, name));
		video_device->init(window);
	}

	virtual void init()
	{
		music = sound_manager->loadStream("CLines music", Filesystem::redirect("CLines.ogg"));
		click = sound_manager->loadSample("click", Filesystem::redirect("button.wav"));

		music->play();
	}

	virtual bool update()
	{
		input->getMouse()->update();

		if(input->getMouse()->isButtonDown(Mouse::BTN_LEFT))
			click->play();

		return true;
	}

	virtual bool render()
	{
		video_device->beginScene();
		video_device->endScene();

		return true;
	}

private:
	SoundPtr music;
	SoundPtr click;
};

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR pCmdLine, int nShowCmd)
{
	try
	{
		SoundTest app(hInstance, "Sound", "sound.log");
		app.run();
	}
	catch (std::exception& e)
	{
		MessageBox(NULL, e.what(), "Fatal error", NULL);
	}
	return 0;
}
